home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8093 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  55 lines

  1. Path: news.netins.net!trg1
  2. From: hhowe@trgnet.com (Harold Howe)
  3. Newsgroups: comp.lang.c++
  4. Subject: Question: passing ptr to private data
  5. Date: Wed, 14 Feb 96 14:45:45 GMT
  6. Organization: Technology Resource Group
  7. Message-ID: <4fsvte$igq@insosf1.netins.net>
  8. NNTP-Posting-Host: desm-20-13.dialup.netins.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #3
  10.  
  11. Greetings.
  12.  
  13. I am currenlty writing a TurboVision application, but my question is about OO 
  14. concepts and would also apply to owl programming.  
  15.  
  16. My application class contains a private structure with configuration 
  17. information.  I need to pass this structure to a dialog box class so the 
  18. structure can be modified.  Currently, I pass the address of the structure, 
  19. which means the dialog class has direct access to the application classes 
  20. private structure.  My code resembles this:
  21.  
  22. class TMyApp: public TApplication
  23.   {
  24.   private:
  25.     ConfigStructure app_config;
  26.     TMyDialog *dlg;
  27.   public:
  28.     void initDlg()
  29.       {
  30.       dlg = new TMyDialog(&app_config);
  31.       }
  32.   ...
  33.   };
  34.  
  35. class TMyDialog : public TDialog
  36.   {
  37.   public:
  38.     TMyDialog(ConfigStructure *cfg);
  39.   private:
  40.     ConfigStucture *dlg_config;
  41.   ...
  42.   ...  plus other functions that interact with dlg_config
  43.   };
  44.  
  45. TMyDialog::TMyDialog(ConfigStructure *cfg)
  46.   {
  47.   dlg_config = cfg;
  48.   }
  49.  
  50. Does this violate encapsulation? Any suggestions and criticisms would be 
  51. appreciated.
  52.  
  53. Harold Howe
  54. hhowe@trgnet.com
  55.